import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// Vue.config.productionTip = false;
import qfSubMenu from "qf-sub-menu" //引入我们的组件
Vue.use(qfSubMenu)
import "./assets/font/iconfont"
import "@/assets/css/common.css"
import "@/assets/css/el-reset.css"
import "./assets/font/iconfont.css"
//  进度条
import nprogress from "nprogress"
import 'nprogress/nprogress.css'
// 路由守卫
router.beforeEach((to,from,next)=>{
  // console.log(to);
  // 打开进度条
  nprogress.start()
  let token=localStorage.getItem('qt-token');
  if (token) {
    if (store.state.userMenu.length === 0) {
      //用户的路由信息(菜单信息)没有了,需要重新发起请求
      store.dispatch('FETCH_MENULIST')
        .then(() => {
          //重新激活动态添加的路由,replace:true 不产生历史记录
          next({ ...to, replace: true })
        })
    } else {
      next()
    }
    } else{
    if(to.path==="/login"){
      next()
    }else{
      next({path:"/login"})
    }
  }
})
// 停止进度条
router.afterEach((to,next)=>{
  nprogress.done()
})

Vue.use(ElementUI);
new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
